
public class p1008_266ms {

	public static//
	// -----
	// -----
	class Main {
		public static void main(String[] args) throws Exception {
			java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
			int size = Integer.parseInt(reader.readLine());
			System.out.println(size);
			for (int i = 0; i < size; i++) {
				System.out.println(trans(reader.readLine()));
			}
		}

		static final java.util.Map<String, Integer> habbMon = new java.util.HashMap<String, Integer>();
		static {
			String[] months = { "pop", "no", "zip", "zotz", "tzec", "xul", "yoxkin", "mol", "chen", "yax", "zac",
					"ceh", "mac", "kankin", "muan", "pax", "koyab", "cumhu", "uayet" };
			for (int i = 0; i < months.length; i++)
				habbMon.put(months[i], i);
		}
		static final String[] tzolkinMon = { "imix", "ik", "akbal", "kan", "chicchan", "cimi", "manik", "lamat",
				"muluk", "ok", "chuen", "eb", "ben", "ix", "mem", "cib", "caban", "eznab", "canac", "ahau" };

		static String trans(String line) {
			String[] parts = line.split("\\.? ");
			int day = Integer.parseInt(parts[2]) * 365 + habbMon.get(parts[1]) * 20 + Integer.parseInt(parts[0]);
			int year = day / 260; // 20*13
			day = day % 260;
			return (day % 13 + 1) + " " + tzolkinMon[day % 20] + " " + year;
		}
	}

	// -----
	// -----

	public static void main(String[] args) throws Exception {
		Judge.run();
	}

}
